#ifndef DIJKSTRA_H
#define DIJKSTRA_H

#include <QtCore>
#include <limits>
#include "database.h"



class Dijkstra {
public:
    struct ShortestPathResult {
        QList<int> path;        // 路径节点序列
        double totalDistance;   // 路径总长度（浮点型）
        bool isValid;           // 是否有效路径
    };

    Dijkstra() = default;

    // 添加带浮点权重的有向边
    void Init();
    // 计算最短路径
    ShortestPathResult calculateShortestPath(int start, int end);
    int addPoint(QVector<double> posiiton);
    QVector<double> correction(QVector<double> position,DataBase::edge edge);
private:
    // 邻接表结构：<节点ID, <目标节点, 浮点权重>>
    QHash<int, QList<QPair<int, double>>> m_graph;
    QVector<QVector<double>> Points;
    // 初始化节点距离为无穷大
    void initialize(QHash<int, double>& dist, QHash<int, int>& prev) const;
    // 构建最短路径
    ShortestPathResult buildResult(const QHash<int, double>& dist,
                                   const QHash<int, int>& prev,
                                   int start, int end) const;


};

#endif // DIJKSTRA_H
